package mb_session;

import entities.RegionCode;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.json.JSONArray;
import org.primefaces.json.JSONException;
import org.primefaces.json.JSONObject;

@ManagedBean(name = "regionCodeController")
@SessionScoped
public class RegionCodeController implements Serializable {

    @EJB
    private ejb_stateless.RegionCodeFacade ejbFacade;
    
        public JSONArray points() throws JSONException {
        String sql = "select  s from RegionCode s where s.coordX is not null";
        JSONArray json = new JSONArray();
        List<RegionCode> quList = ejbFacade.findAll(sql);
        for (int j = 0; j < quList.size(); j++) {
            JSONObject jo = new JSONObject();
            jo.put("point", quList.get(j).getId());
            jo.put("pointx", quList.get(j).getCoordX());
            jo.put("pointy", quList.get(j).getCoordY());
            json.put(jo);
        }
        return json;
    }
     public JSONArray pointsSheng() throws JSONException {
String sql = "select  s from RegionCode s where s.coordX is not null";
        JSONArray json = new JSONArray();
        List<RegionCode> quList = ejbFacade.findAll(sql);
        for (int j = 0; j < quList.size(); j++) {
            JSONObject jo = new JSONObject();
            jo.put("point", quList.get(j).getId());
            jo.put("pointx", quList.get(j).getCoordX());
            jo.put("pointy", quList.get(j).getCoordY());
            json.put(jo);
        }
        return json;
    }
}
